package com.sunnyweather.android.ui.place

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.sunnyweather.android.R
import com.sunnyweather.android.logic.model.Place
import java.util.zip.Inflater

/**
 *@author DuJinliang
 *2021/8/26
 */
class PlaceAdapter(val placeList : List<Place>) : RecyclerView.Adapter<PlaceAdapter.holder>() {

    inner class holder(view : View) : RecyclerView.ViewHolder(view){
        val placeName = view.findViewById<TextView>(R.id.placeName)
        val placeAddress = view.findViewById<TextView>(R.id.placeAddress)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): holder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.place_item, parent, false)

        return holder(view)
    }

    override fun onBindViewHolder(holder: holder, position: Int) {
        val place = placeList[position]

        holder.placeName.text = place.name
        holder.placeAddress.text = place.address
    }

    override fun getItemCount() = placeList.size

}